﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Method.DateTime
{
    //这是发表文章/评论的时间
    public static class GetPastTime
    {
        /// <summary>
        /// 获取发表时间
        /// </summary>
        /// <param name="Cid"></param>
        /// <returns></returns>
        public static string getTime(string Cid)
        {
            string oldTIme = Cid;

            string 年 = oldTIme.Substring(0, 4);
            string 月 = oldTIme.Substring(4, 2);
            string 日 = oldTIme.Substring(6, 2);
            string 时 = oldTIme.Substring(8, 2);
            string 分 = oldTIme.Substring(10, 2);

            var newTime = System.DateTime.Now.ToString("yyyyMMddHHmmssfff");

            var year = Convert.ToInt32(newTime.Substring(0, 4)) - Convert.ToInt32(年);
            if (year is 0)
            {
                var month = Convert.ToInt32(newTime.Substring(4, 2)) - Convert.ToInt32(月);
                if (month is 0)
                {
                    //当天的显示时间
                    var day = Convert.ToInt32(newTime.Substring(6, 2)) - Convert.ToInt32(日);
                    if (day is 0)
                    {
                        var hour = Convert.ToInt32(newTime.Substring(8, 2)) - Convert.ToInt32(时);
                        if (hour is 0)
                        {
                            //显示分钟
                            var min = Convert.ToInt32(newTime.Substring(10, 2)) - Convert.ToInt32(分);
                            if (min is 0)
                                return "刚刚";
                            else
                                return $"{min}分钟前";
                        }
                        else
                            if (hour <= 3)
                                return $"{hour}小时前";
                            else
                                return $"{时}时{分}分";
                    }
                    else//以前
                        if (day <= 3)
                            return $"{day}天前";
                        else
                            return $"{月}月{日}日";
                }
                else
                    return $"{月}月{日}日";
            }
            else
                return $"{年}年{月}月{日}日";
        }
    }
}
